{__NOLAYOUT__}
<!DOCTYPE html>
<html id="scroll1">
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
	<title></title>
	{include file="public/script" /}
</head>
<body>
	<div class="sectionH sectionH2  mui-clearfix">
		<header class="mui-bar mui-bar-nav" style="">
			<a class="mui-icon mui-icon-left-nav  mui-pull-left" href="javascript:history.back(-1)" style="color: #727272;"></a>
			<h1 class="mui-title">{$chat_maninfo['real_name']}</h1>
			<a style="padding-top:10px" class="mui-icon mui-pull-right right1" href="{:url('Chat/history',['getid'=>$getuserid])}"><img src="__STATIC__/www/images/lishi.png"/></a>
		</header>
	</div>
	<div class="kong1"></div>
	<div class="section2">
		
		<div class="container">
			<div class="section2-1 mui-clearfix">
				{volist name="chat_list" id="v"}
				<div {if condition="$getuserid == $v['send_uid']"}class="mai-{$v['ty']}  mui-clearfix"{else/}class="shang-{$v['ty']}  mui-clearfix" {/if}>
					<div class="logo">
						{if condition="$getuserid == $v['send_uid']"}
						<img src="{$chat_maninfo.avatar|default='/static/default_avatar.png'}"/>
						{else /}
						<img src="{$uinfo.avatar|default='/static/default_avatar.png'}"/>
						{/if}
					</div>
					<div {if condition="$getuserid == $v['send_uid']"}class="shijian leftx"{else /}class="shijian lefty"{/if}>
						<span>{$v.ctime}</span>
					</div>

					<div class="center">
						<span>{$v.content}</span>
					</div>
					<input type='hidden' value="{$v.id}" />
				</div>
				{/volist}
			</div>
		</div>
	</div>
	<div class="kong"></div>
	<div class="section3">
			<div class="section3-1 mui-clearfix" >
				<input placeholder="发送私信给TA吧" type="text" autocomplete="off" id="content" maxlength="255" />
				<img id="chatSub" src="__STATIC__/www/images/message_icon_send.png" class="tggy"/>
			</div>
	</div>
</body>

<script type="text/javascript">

$(function (){
    $('html, body, .prolist').animate({scrollTop: $(document).height()}, 1);
    var getid = "{$getuserid}";
    $("#chatSub").click(function(){
        var content = $("#content").val();
        if(content == ''){
			mui.toast('请输入您想说的话！');
			return false;
		}
		if($(this).hasClass('sending')){
            mui.toast('发送中，请稍候...');
            return false;
		}

        $.ajax({
            type:'post',
            url:"{:url('Chat/saveMessage')}",
            data:{content:content,getid:getid},
            cache:false,
            dataType:'JSON',
            success:function(data){
                if(data.result_code==='0000'){
                    $("#chatSub").removeClass('sending');
                    location.reload();
                }else if(data.result_code==='1111'){
                    mui.alert('请登录','',function(){
                        window.location.href='/Login/login';
                    });
                }else{
                    mui.toast(data.result_info);
                    $("#chatSub").removeClass('sending');
                }

            },
            error:function(e){
                $("#chatSub").removeClass('sending');
            },
            beforeSend:function(e){
                $("#chatSub").addClass('sending');
            }
        });
	});
    var timeing = setTimeout(opa, 3000);
    function opa() {
        loadmessage();
        clearTimeout(timeing); //清除上一次的定时器，否则会无限开多个
        setTimeout(opa, 3000);//方法中调用定时器实现循环
    }

    //拉取信息
    function loadmessage(){

        var lastid = $(".section2-1").find("input:last").val();
        if(lastid==undefined){
            return false;
        }

        var img_dui = "{$chat_maninfo.avatar|default='/static/default_avatar.png'}";
		var img_wo = "{$uinfo.avatar|default='/static/default_avatar.png'}";
        $.ajax({
            type:'post',
            url:"{:url('Chat/loadMessage')}",
            data:{lastid:lastid,getid:getid},
            cache:false,
            dataType:'JSON',
            success:function(data){
                if(data.result_code==='0000'){
                    var list = data.result_data.list;
					var table = document.body.querySelector('.section2-1');
                    if(list.id>0){
                        var div = document.createElement('div');
                        if(getid == list['send_uid']){
                            var headimg = img_dui;
                            var classname = 'shijian leftx';
                            div.className = 'mai-'+list.ty+'  mui-clearfix';
                        }else{
                            var headimg = img_wo;
                            var classname = 'shijian lefty';
                            div.className = 'shang-'+list.ty+'  mui-clearfix';
                        }

                        var html = 	'<div class="logo">'+
                    					'<img src="'+headimg+'"/>'+
									'</div>'+
                        			'<div class="'+classname+'">'+
                    					'<span>'+list.ctime+'</span>'+
                        			'</div>'+
									'<div class="center">'+
                        				'<span>'+list.content+'</span>'+
                        			'</div>'+
                        			'<input type="hidden" value="'+list.id+'" />';

                        div.innerHTML = html;
                        table.appendChild(div);
                        $('html, body, .prolist').animate({scrollTop: $(document).height()}, 1);
                    }
                }else if(data.result_code==='1111'){
                    mui.alert('请登录','',function(){
                        window.location.href='/Login/login';
                    });
                }else{
                    mui.toast(data.result_info);
                }

            }
        });
	}

});
</script>
</html>